package lium.lbs.lbsim.activity

import android.content.Intent
import android.os.Bundle
import android.view.Gravity
import android.view.View
import com.buz.hjcdriver.bean.GetUserInfoResultBean
import com.lmlibrary.Constants
import com.lmlibrary.bean.ResponseBean
import com.lzy.okgo.model.Response
import kotlinx.android.synthetic.main.activity_creategroup.*
import lium.lbs.lbsim.R
import lium.lbs.lbsim.jgchat.utils.photovideo.takevideo.utils.LogUtils
import lium.lbs.lbsim.utils.IAlertDialog
import lium.lbs.lbsim.utils.SpUtils
import lium.lbs.lbsim.utils.UserUtils
import lium.lbs.lbsim.utils.callbck.JsonCallback
import java.util.HashMap

class CreateGroupSetGroupNameActivity : BaseActivity() {

    internal var dialog: IAlertDialog? = null
    override fun getLayoutId(): Int {
        return R.layout.activity_creategroup
    }

    override fun initView(savedInstanceState: Bundle?) {
        setTitleWithBack("创建群聊")
        addOnClickListeners(R.id.btn_creategroup)
    }

    override fun onClick(v: View?) {
        super.onClick(v)
        when (v!!.id) {
            R.id.btn_creategroup -> {
                getmyinfo()

            }
        }
    }

    private fun getmyinfo() {
        //隐示获取个人信息
        val intent = Intent()
        intent.setClass(this, CreateGroupPayActivity::class.java)
        val param = HashMap<String, String>()
        postData("/member/getMemberInfo", param, object : JsonCallback<ResponseBean<GetUserInfoResultBean>>(this) {
            override fun onSuccess(response: Response<ResponseBean<GetUserInfoResultBean>>) {
                UserUtils.login(response.body().data.memberId + "")
                LogUtils.e("body-isVerified" + response.body().data.isVerified)

                if (response.body().data.isVerified == 0) {
                    requestPerFailed()
                } else {
                    intent.putExtra("name", tv_qunname.text.toString())
                    startActivity(intent)
                    finish()
                }


            }
        })
    }

    private fun requestPerFailed() {
        if (dialog == null) {
            dialog = IAlertDialog(this, IAlertDialog.LayoutStyle.DEFAULT, Gravity.CENTER)
            dialog!!.setMessage("您还没有进行实名认证，是否进行实名认证？")
            dialog!!.setPositiveMsg("去实名")
            dialog!!.setPositiveOnClickListener { dialog, which ->
                val intent = Intent(this, RenZhengActivity::class.java)
                startActivityForResult(intent, 100)
            }
            dialog!!.setNegativeMsg("再想想")
            dialog!!.setNegativeOnClickListener { dialog, which ->
                finish()
            }
        }
        dialog!!.show()
    }

    override fun getNetWorkData() {
    }


}

